home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Dev / misc / WHDLoad_dev.lha / WHDLoad / Src / sources / whdload / kick13.s < prev    next >
Encoding:
Text File  |  2003-12-10  |  19.8 KB  |  932 lines

  1. ;*---------------------------------------------------------------------------
  2. ;  :Modul.    kick13.s
  3. ;  :Contents.    interface code and patches for kickstart 1.3
  4. ;  :Author.    Wepl, Psygore
  5. ;  :Version.    $Id: kick13.s 0.52 2003/12/10 14:22:49 wepl Exp wepl $
  6. ;  :History.    19.10.99 started
  7. ;        18.01.00 trd_write with writeprotected fixed
  8. ;             diskchange fixed
  9. ;        24.01.00 reworked to assemble with Asm-Pro
  10. ;        20.02.00 problems with Snoop/S on 68060 fixed
  11. ;        21.02.00 cbswitch added (cop2lc)
  12. ;        22.02.00 free memory count added
  13. ;        01.03.00 wait in _trd_changedisk removed because deadlocks
  14. ;        09.03.00 adapted for whdload v11
  15. ;        17.03.00 most stuff from SetPatch 1.38 added
  16. ;        20.03.00 some fixes for 68060 and snoop
  17. ;        16.04.00 loadview fixed
  18. ;        11.05.00 SetPatch can be enabled/disabled via a defined label
  19. ;        19.06.01 ChkBltWait problem fixed in blitter init
  20. ;        15.07.01 using time provided by whdload to init timer.device
  21. ;        02.08.01 exec.Supervisor fixed (to work with exec.SuperState)
  22. ;        03.08.01 NOFPU->NEEDFPU changed, DISKSONBOOT added
  23. ;             bug in trackdisk fixed (endio missing on error)
  24. ;        04.08.01 flushcache and callback for dos.LoadSeg added
  25. ;        05.08.01 hd supported started
  26. ;        01.09.01 trap #15 to trap #14 changed in _Supervisor (debug rnc)
  27. ;             BLACKSCREEN added
  28. ;        08.11.01 Supervisor patch removed, slaves now require
  29. ;             WHDLF_EmulPriv to be set
  30. ;        27.11.01 fs enhanced
  31. ;        17.12.01 beta finished for Elvira
  32. ;        04.01.02 MAXFILENAME removed
  33. ;        16.01.02 support for Guru Meditation added
  34. ;        30.01.02 write cache added
  35. ;        06.02.02 cleanup
  36. ;        27.02.02 trailing slash in .buildname removed
  37. ;        05.03.02 modification of filter by kick disabled (Psygore)
  38. ;        17.04.02 POINTERTICKS added
  39. ;             ACTION_DELETE_OBJECT fixed for nonexistent objects
  40. ;             filesystem handler moved to kickfs.s
  41. ;        18.11.02 illegal trackdisk-patches enabled if DEBUG
  42. ;        30.11.02 FONTHEIGHT added
  43. ;        13.02.03 snoopbug at $6efe fixed (Psygore)
  44. ;             STACKSIZE added (Captain HIT)
  45. ;        30.03.03 _bootearly/block made returnable
  46. ;        06.04.03 cache option added
  47. ;        15.05.03 patch for exec.ExitIntr to avoid double ints
  48. ;        11.06.03 patch for access fault from EndCLI (JOTD)
  49. ;        20.06.03 adapted for whdload v16
  50. ;        25.06.03 _dos_assign parameter change
  51. ;        09.12.03 keyboard acknowledgment fixed
  52. ;  :Requires.    -
  53. ;  :Copyright.    Public Domain
  54. ;  :Language.    68000 Assembler
  55. ;  :Translator.    Barfly 2.9, Asm-Pro 1.16, PhxAss 4.38
  56. ;  :To Do.
  57. ;---------------------------------------------------------------------------*
  58.  
  59.     INCLUDE    lvo/exec.i
  60.     INCLUDE    lvo/graphics.i
  61.     INCLUDE    devices/trackdisk.i
  62.     INCLUDE    exec/memory.i
  63.     INCLUDE    graphics/gfxbase.i
  64.  
  65. KICKVERSION    = 34
  66. KICKCRC        = $f9e3                ;34.005
  67.  
  68. ;============================================================================
  69.  
  70.     IFD    slv_Version
  71.     IFNE    slv_Version-16
  72.     FAIL    must be slave version 16
  73.     ENDC
  74.  
  75. KICKSIZE    = $40000            ;34.005
  76. BASEMEM        = CHIPMEMSIZE
  77. EXPMEM        = KICKSIZE+FASTMEMSIZE
  78.  
  79. slv_base    SLAVE_HEADER            ;ws_Security + ws_ID
  80.         dc.w    slv_Version        ;ws_Version
  81.         dc.w    WHDLF_EmulPriv|slv_Flags;ws_flags
  82. _basemem    dc.l    BASEMEM            ;ws_BaseMemSize
  83.         dc.l    0            ;ws_ExecInstall
  84.         dc.w    _boot-slv_base        ;ws_GameLoader
  85.         dc.w    slv_CurrentDir-slv_base    ;ws_CurrentDir
  86.         dc.w    0            ;ws_DontCache
  87. _keydebug    dc.b    0            ;ws_keydebug
  88. _keyexit    dc.b    slv_keyexit        ;ws_keyexit
  89. _expmem        dc.l    EXPMEM            ;ws_ExpMem
  90.         dc.w    slv_name-slv_base    ;ws_name
  91.         dc.w    slv_copy-slv_base    ;ws_copy
  92.         dc.w    slv_info-slv_base    ;ws_info
  93.         dc.w    slv_kickname-slv_base    ;ws_kickname
  94.         dc.l    KICKSIZE        ;ws_kicksize
  95.         dc.w    KICKCRC            ;ws_kickcrc
  96.     ENDC
  97.  
  98. ;============================================================================
  99. ; the following is to avoid "Error 86: Internal global optimize error" with
  100. ; BASM, which is caused by "IFD _label" and _label is defined after the IFD
  101.  
  102.     IFND BOOTBLOCK
  103.     IFD _bootblock
  104. BOOTBLOCK = 1
  105.     ENDC
  106.     ENDC
  107.     IFND BOOTDOS
  108.     IFD _bootdos
  109. BOOTDOS = 1
  110.     ENDC
  111.     ENDC
  112.     IFND BOOTEARLY
  113.     IFD _bootearly
  114. BOOTEARLY = 1
  115.     ENDC
  116.     ENDC
  117.     IFND CBDOSREAD
  118.     IFD _cb_dosRead
  119. CBDOSREAD = 1
  120.     ENDC
  121.     ENDC
  122.     IFND CBDOSLOADSEG
  123.     IFD _cb_dosLoadSeg
  124. CBDOSLOADSEG = 1
  125.     ENDC
  126.     ENDC
  127.  
  128. ;============================================================================
  129.  
  130. _boot        lea    (_resload,pc),a1
  131.         move.l    a0,(a1)                ;save for later use
  132.         move.l    a0,a5                ;A5 = resload
  133.  
  134.     IFD CACHE
  135.     ;enable caches
  136.         move.l    #WCPUF_Base_NC|WCPUF_Exp_CB|WCPUF_Slave_CB|WCPUF_IC|WCPUF_DC|WCPUF_BC|WCPUF_SS|WCPUF_SB,d0
  137.         move.l    #WCPUF_All,d1
  138.         jsr    (resload_SetCPU,a5)
  139.     ENDC
  140.  
  141.     ;relocate some addresses
  142.         lea    (_cbswitch,pc),a0
  143.         lea    (_cbswitch_tag,pc),a1
  144.         move.l    a0,(a1)
  145.  
  146.     ;get tags
  147.         lea    (_tags,pc),a0
  148.         jsr    (resload_Control,a5)
  149.  
  150.     IFND slv_Version
  151.     ;load kickstart
  152.         move.l    #KICKSIZE,d0            ;length
  153.         move.w    #KICKCRC,d1            ;crc16
  154.         lea    (slv_kickname,pc),a0        ;name
  155.         jsr    (resload_LoadKick,a5)
  156.     ENDC
  157.  
  158.     ;patch the kickstart
  159.         lea    (kick_patch,pc),a0
  160.         move.l    (_expmem,pc),a1
  161.         jsr    (resload_Patch,a5)
  162.  
  163.     ;call
  164. kick_reboot    move.l    (_expmem,pc),a0
  165.         jmp    (2,a0)                ;original entry
  166.  
  167. kick_patch    PL_START
  168.         PL_S    $d2,$fe-$d2
  169.         PL_L    $106,$02390002            ;skip LED power off (and.b #~CIAF_LED,$bfe001)
  170.         PL_CW    $132                ;color00 $444 -> $000
  171.         PL_CW    $25a                ;color00 $888 -> $000
  172.     IFD HRTMON
  173.         PL_PS    $286,kick_hrtmon
  174.     ENDC
  175.         PL_PS    $422,exec_flush
  176.         PL_L    $4f4,-1                ;disable search for residents at $f00000
  177.         PL_S    $50C,$514-$50C            ;skip LED power on
  178.         PL_P    $546,kick_detectcpu
  179.         PL_P    $592,kick_detectchip
  180.         PL_P    $5f0,kick_reboot        ;reboot (reset)
  181.         PL_P    $61a,kick_detectfast
  182.         PL_P    $ebc,exec_ExitIntr
  183.         PL_P    $1354,exec_snoop1
  184.         PL_PS    $14b6,exec_SetFunction
  185.         PL_PS    $15b2,exec_MakeFunctions
  186.     IFD MEMFREE
  187.         PL_P    $1826,exec_AllocMem
  188.     ENDC
  189.         PL_S    $4964,$4978-$4964        ;skip disk unit detect
  190.         PL_P    $4adc,disk_getunitid
  191.         PL_S    $4cce,4                ;skip autoconfiguration at $e80000
  192.         PL_PS    $6d70,gfx_vbserver
  193.         PL_PS    $6d86,gfx_snoop1
  194.         PL_L    $6efe,$08390005            ;snoop bug ('and.w #$20,$DFF01E' -> 'btst #5,$DFF01E')
  195.         PL_PS    $ad5e,gfx_setcoplc
  196.         PL_S    $ad7a,6                ;avoid ChkBltWait problem
  197.         PL_S    $aecc,$e4-$cc            ;skip color stuff & strange gb_LOFlist set
  198.         PL_P    $af96,gfx_detectgenlock
  199.         PL_P    $b00c,gfx_detectdisplay
  200.         PL_PS    $d5be,gfx_fix1            ;gfx_LoadView
  201.     IFD FONTHEIGHT
  202.         PL_B    $1b96c,FONTHEIGHT
  203.     ENDC
  204.     IFD BLACKSCREEN
  205.         PL_C    $1b9d2,6            ;color17,18,19
  206.         PL_C    $1b9da,8            ;color0,1,2,3
  207.     ENDC
  208.     IFD POINTERTICKS
  209.         PL_W    $1b9d8,POINTERTICKS
  210.     ENDC
  211.         PL_PS    $2528a,keyboard_start
  212.         PL_PS    $253a2,keyboard_end
  213.     IFD HDINIT
  214.         PL_PS    $28452,hd_init            ;enter while starting strap
  215.     ENDC
  216.     IFD BOOTEARLY
  217.         PL_PS    $284fa,kick_bootearly
  218.     ENDC
  219.     IFD BOOTBLOCK
  220.         PL_PS    $285c6,kick_bootblock        ;a1=ioreq a4=buffer a6=execbase
  221.     ENDC
  222.         PL_P    $28f88,timer_init
  223.         PL_P    $2960c,trd_task
  224.         PL_P    $29cfa,trd_format
  225.         PL_P    $2a0e2,trd_motor
  226.         PL_P    $2a3b4,trd_readwrite
  227.         PL_PS    $2a6d6,trd_protstatus
  228.     IFD DEBUG
  229.         PL_L    $29c54,-1            ;disable asynchron io
  230.         PL_I    $2a19c                ;empty dbf-loop in trackdisk.device
  231.         PL_I    $2a5d8                ;internal readwrite
  232.         PL_I    $2a694                ;trd_seek
  233.         PL_I    $2af68                ;trd_rawread
  234.         PL_I    $2af6e                ;trd_rawwrite
  235.     ENDC
  236.         PL_PS    $33ef0,dos_init
  237.         PL_PS    $3568c,dos_endcli
  238.         PL_PS    $36e4c,dos_LoadSeg
  239.     IFD BOOTDOS
  240.         PL_PS    $38748,dos_bootdos
  241.     ENDC
  242.     IFD STACKSIZE
  243.         PL_L    $387be,STACKSIZE/4
  244.     ENDC
  245.         PL_PS    $3c9b6,dos_1
  246.     ;the following stuff is from SetPatch 1.38
  247.     IFD SETPATCH
  248.         PL_P    $11b0,exec_UserState
  249.         PL_P    $1696,exec_FindName
  250.         PL_P    $195a,exec_AllocEntry
  251.         PL_PS    $582c,gfx_MrgCop
  252.         PL_PS    $7f66,gfx_SetFont
  253.         PL_P    $7fa6,gfx_SetSoftStyle
  254.     ENDC
  255.         PL_END
  256.  
  257. ;============================================================================
  258.  
  259. kick_detectfast
  260.     IFEQ FASTMEMSIZE
  261.         sub.l    a4,a4
  262.     ELSE
  263.         move.l    (_expmem,pc),a4
  264.         add.l    #KICKSIZE,a4
  265.         move.l    a4,($1f0-$1ea,a5)
  266.         move.l    a4,($1fc-$1ea,a5)
  267.         add.l    #FASTMEMSIZE,a4
  268.         bsr    _flushcache
  269.     ENDC
  270.         jmp    (a5)
  271.  
  272. kick_detectchip    move.l    #CHIPMEMSIZE,a3
  273.         jmp    (a5)
  274.  
  275.     IFD HRTMON
  276. kick_hrtmon    move.l    a4,d0
  277.         bne    .1
  278.         move.l    a3,d0
  279. .1        sub.l    #8,d0            ;hrt reads too many from stack -> avoid af
  280.         rts
  281.     ENDC
  282.  
  283. kick_detectcpu    move.l    (_attnflags,pc),d0
  284.     IFND NEEDFPU
  285.         and.w    #~(AFF_68881|AFF_68882|AFF_FPU40),d0
  286.     ENDC
  287.         rts
  288.  
  289. exec_ExitIntr    tst.w    (_custom+intreqr)    ;delay to make sure int is cleared
  290.         movem.l    (a7)+,d0-d1/a0-a1/a5-a6
  291.         rte
  292.  
  293.     ;move.w (a7)+,($dff09c) does not work with Snoop/S on 68060
  294. exec_snoop1    move.w    (a7),($dff09c)
  295.         addq.l    #2,a7
  296.         rts
  297.  
  298. exec_MakeFunctions
  299.         subq.l    #8,a7
  300.         move.l    (8,a7),(a7)
  301.         move.l    a3,(4,a7)        ;original
  302.         lea    (_flushcache,pc),a3
  303.         move.l    a3,(8,a7)
  304.         moveq    #0,d0            ;original
  305.         move.l    a2,d1            ;original
  306.         rts
  307.  
  308. exec_SetFunction
  309.         move.l    (a7)+,d1
  310.         pea    (_flushcache,pc)
  311.         move.l    d1,-(a7)
  312.         bset    #1,(14,a1)        ;original
  313.         rts
  314.  
  315. exec_flush    lea    (_custom),a0        ;original
  316.         bra    _flushcache
  317.  
  318.     IFD MEMFREE
  319. exec_AllocMem    movem.l    d0-d1/a0-a1,-(a7)
  320.         move.l    #MEMF_LARGEST|MEMF_CHIP,d1
  321.         jsr    (_LVOAvailMem,a6)
  322.         move.l    (MEMFREE),d1
  323.         beq    .3
  324.         cmp.l    d1,d0
  325.         bhi    .1
  326. .3        move.l    d0,(MEMFREE)
  327. .1        move.l    #MEMF_LARGEST|MEMF_FAST,d1
  328.         jsr    (_LVOAvailMem,a6)
  329.         move.l    (MEMFREE+4),d1
  330.         beq    .4
  331.         cmp.l    d1,d0
  332.         bhi    .2
  333. .4        move.l    d0,(MEMFREE+4)
  334. .2        movem.l    (a7)+,d0-d1/a0-a1
  335.         movem.l    (a7)+,d2-d3/a2
  336.         rts
  337.     ENDC
  338.  
  339.     IFD SETPATCH
  340.  
  341. exec_AllocEntry    movem.l    d2/d3/a2-a4,-(sp)
  342.         movea.l    a0,a2
  343.         moveq    #0,d3
  344.         move.w    (14,a2),d3
  345.         move.l    d3,d0
  346.         lsl.l    #3,d0
  347.         addi.l    #$10,d0
  348.         move.l    #$10000,d1
  349.         jsr    (-$C6,a6)
  350.         movea.l    d0,a3
  351.         movea.l    d0,a4
  352.         tst.l    d0
  353.         beq.b    .BD0
  354.         move.w    d3,(14,a3)
  355.         lea    ($10,a2),a2
  356.         lea    ($10,a3),a3
  357.         moveq    #0,d2
  358. .B78        move.l    (0,a2),d1
  359.         move.l    (4,a2),d0
  360.         move.l    d0,(4,a3)
  361.         beq.b    .B8E
  362.         jsr    (_LVOAllocMem,a6)
  363.         tst.l    d0
  364.         beq.b    .BA4
  365. .B8E        move.l    d0,(0,a3)
  366.         addq.l    #8,a2
  367.         addq.l    #8,a3
  368.         addq.w    #1,d2
  369.         subq.l    #1,d3
  370.         bne.b    .B78
  371.         move.l    a4,d0
  372. .B9E        movem.l    (sp)+,d2/d3/a2-a4
  373.         rts
  374.  
  375. .BA4        subq.w    #1,d2
  376.         bmi.b    .BB8
  377.         subq.l    #8,a3
  378.         movea.l    (0,a3),a1
  379.         move.l    (4,a3),d0
  380.         jsr    (_LVOFreeMem,a6)
  381.         bra.b    .BA4
  382.  
  383. .BB8        moveq    #0,d0
  384.         move.w    (14,a4),d0
  385.         lsl.l    #3,d0
  386.         addi.l    #$10,d0
  387.         movea.l    a4,a1
  388.         jsr    (_LVOFreeMem,a6)
  389.         move.l    (0,a2),d0
  390. .BD0        bset    #$1F,d0
  391.         bra.b    .B9E
  392.  
  393. exec_UserState    move.l    (sp)+,d1
  394.         move.l    sp,usp
  395.         movea.l    d0,sp
  396.         movea.l    a5,a0
  397.         lea    (.B18,pc),a5
  398.         jmp    (_LVOSupervisor,a6)
  399.  
  400. .B18        movea.l    a0,a5
  401.         move.l    d1,(2,sp)
  402.         andi.w    #$DFFF,(sp)
  403.         rte
  404.  
  405. exec_FindName    move.l    a2,-(sp)
  406.         movea.l    a0,a2
  407.         move.l    a1,d1
  408.         move.l    (a2),d0
  409.         beq.b    .FDC
  410. .FBE        movea.l    d0,a2
  411.         move.l    (a2),d0
  412.         beq.b    .FDC
  413.         tst.l    (10,a2)
  414.         beq.b    .FBE
  415.         movea.l    (10,a2),a0
  416.         movea.l    d1,a1
  417. .FD0        cmpm.b    (a0)+,(a1)+
  418.         bne.b    .FBE
  419.         tst.b    (-1,a0)
  420.         bne.b    .FD0
  421.         move.l    a2,d0
  422. .FDC        movea.l    d1,a1
  423.         movea.l    (sp)+,a2
  424.         rts
  425.  
  426.     ENDC
  427.  
  428.     IFD BOOTEARLY
  429. kick_bootearly    movem.l    d0-a6,-(a7)
  430.         bsr    _bootearly
  431.         movem.l    (a7)+,d0-a6
  432.         lea    ($2c,a5),a1        ;original
  433.         moveq    #0,d0            ;original
  434.         rts
  435.     ENDC
  436.  
  437.     IFD BOOTBLOCK
  438. kick_bootblock    movem.l    d2-d7/a2-a6,-(a7)
  439.         bsr    _bootblock
  440.         movem.l    (a7)+,d2-d7/a2-a6
  441.         tst.l    d0            ;original
  442.         rts
  443.     ENDC
  444.  
  445. ;============================================================================
  446.  
  447. gfx_vbserver    lea    (_cbswitch_cop2lc,pc),a6
  448.         move.l    d0,(a6)
  449.         lea    ($bfd000),a6        ;original
  450.         rts
  451.  
  452. _cbswitch    move.l    (_cbswitch_cop2lc,pc),(_custom+cop2lc)
  453.         jmp    (a0)
  454.  
  455.     ;move (custom),(cia) does not work with Snoop/S on 68060
  456. gfx_snoop1    move.b    (vhposr,a0),d0
  457.         move.b    d0,(ciatodlow,a6)
  458.         rts
  459.  
  460. gfx_detectgenlock
  461.         moveq    #0,d0
  462.         rts
  463.  
  464. gfx_detectdisplay
  465.         moveq    #4,d0            ;pal
  466.         move.l    (_monitor,pc),d1
  467.         cmp.l    #PAL_MONITOR_ID,d1
  468.         beq    .1
  469.         moveq    #1,d0            ;ntsc
  470. .1        rts
  471.  
  472. gfx_setcoplc    moveq    #-2,d0
  473.         move.l    d0,(a3)+
  474.         move.l    a3,(cop2lc,a4)        ;original
  475.         move.l    a3,(gb_LOFlist,a2)
  476.         move.l    a3,(gb_SHFlist,a2)
  477.         move.l    d0,(a3)+
  478.         clr.w    (color+2,a4)
  479.         add.l    #$ad72-$ad5e-6,(a7)
  480.         rts
  481.  
  482.     ;somewhere there will used a empty view, too stupid
  483. gfx_fix1    move.l    (v_LOFCprList,a1),d0
  484.         beq    .s1
  485.         move.l    d0,a0
  486.         move.l    (4,a0),(gb_LOFlist,a3)
  487. .s1        move.l    (v_SHFCprList,a1),d0
  488.         beq    .s2
  489.         move.l    d0,a0
  490.         move.l    (4,a0),(gb_SHFlist,a3)
  491. .s2        add.l    #$d5d2-$d5be-6,(a7)
  492.         rts
  493.  
  494.     IFD SETPATCH
  495.  
  496. gfx_MrgCop    move.w    ($10,a1),d0
  497.         move.w    ($9E,a6),d1
  498.         eor.w    d1,d0
  499.         andi.w    #4,d0
  500.         beq.b    .F58
  501.         and.w    ($10,a1),d0
  502.         beq.b    .F58
  503.         movem.l    a2/a3,-(sp)
  504.         movea.l    a1,a2
  505.         movea.l    a1,a3
  506. .F2E        move.l    (a3),d0
  507.         beq.b    .F52
  508.         movea.l    d0,a3
  509.         move.w    ($20,a3),d0
  510.         move.w    #$2000,d1
  511.         and.w    d0,d1
  512.         beq.b    .F2E
  513.         move.w    #4,d1
  514.         and.w    d0,d1
  515.         beq.b    .F2E
  516.         movea.l    a2,a0
  517.         movea.l    a3,a1
  518.         jsr    (_LVOMakeVPort,a6)
  519.         bra.b    .F2E
  520. .F52        movea.l    a2,a1
  521.         movem.l    (sp)+,a2/a3
  522. .F58
  523.         move.l    a1,-(a7)        ;original
  524.         pea    (.ret,pc)
  525.         move.l    (8,a7),-(a7)
  526.         add.l    #-6-$582c+$a5b4,(a7)
  527.         rts
  528.  
  529. .ret        addq.l    #8,a7
  530.         rts
  531.  
  532. gfx_SetFont    move.l    a0,d0
  533.         beq.b    .FAC
  534.         move.l    a1,d0
  535.         beq.b    .FAC
  536.         move.w    ($14,a0),($3a,a1)    ;original
  537.         rts
  538.  
  539. .FAC        addq.l    #4,a7
  540.         rts
  541.  
  542. gfx_SetSoftStyle
  543.         move.l    d2,-(sp)
  544.         moveq    #0,d2
  545.         movem.l    d0/d1/a0/a1,-(sp)
  546.         jsr    (_LVOAskSoftStyle,a6)
  547.         move.b    d0,d2
  548.         movem.l    (sp)+,d0/d1/a0/a1
  549.         movea.l    ($34,a1),a0
  550.         and.b    d2,d1
  551.         move.b    ($38,a1),d2
  552.         and.b    d1,d0
  553.         not.b    d1
  554.         and.b    d1,d2
  555.         or.b    d0,d2
  556.         move.b    d2,($38,a1)
  557.         or.b    ($16,a0),d2
  558.         move.l    d2,d0
  559.         move.l    (sp)+,d2
  560.         rts
  561.  
  562.     ENDC
  563.  
  564. ;============================================================================
  565.  
  566. disk_getunitid
  567.     IFLT NUMDRIVES
  568.         cmp.l    #1,d0            ;at least one drive
  569.         bcs    .set
  570.         cmp.l    (_custom1,pc),d0
  571.     ELSE
  572.         subq.l    #NUMDRIVES,d0
  573.     ENDC
  574. .set        scc    d0
  575.         ext.w    d0
  576.         ext.l    d0
  577.         rts
  578.  
  579. ;============================================================================
  580. ; kick13 does not provide fast and fine access to cia timers, therfore we
  581. ; use the rasterbeam, required minimum waiting is 75µs, one rasterline is
  582. ; 63.5µs a this results in min=127µs max=190.5µs
  583.  
  584. keyboard_start    or.b    #CIACRAF_SPMODE,(ciacra,a0)
  585.         clr.b    (ciasdr,a0)
  586.         lea    (_keyboarddelay,pc),a1
  587.         move.b    (_custom+vhposr),(a1)
  588.         rts
  589.  
  590. keyboard_end    move.w    (_keyboarddelay,pc),d1
  591.         lea    (_custom),a1
  592. .wait1        cmp.b    (vhposr,a1),d1
  593.         beq    .wait1
  594.         move.b    (vhposr,a1),d1
  595. .wait2        cmp.b    (vhposr,a1),d1
  596.         beq    .wait2
  597.         move.b    (vhposr,a1),d1
  598. .wait3        cmp.b    (vhposr,a1),d1
  599.         beq    .wait3
  600.         addq.l    #2,(a7)
  601.         and.b    #~(CIACRAF_SPMODE),(_ciaa+ciacra)
  602.         rts
  603.  
  604. ;============================================================================
  605.  
  606. timer_init    move.l    (_time,pc),a0
  607.         move.l    (whdlt_days,a0),d0
  608.         mulu    #24*60,d0
  609.         add.l    (whdlt_mins,a0),d0
  610.         move.l    d0,d1
  611.         lsl.l    #6,d0            ;*64
  612.         lsl.l    #2,d1            ;*4
  613.         sub.l    d1,d0            ;=*60
  614.         move.l    (whdlt_ticks,a0),d1
  615.         divu    #50,d1
  616.         ext.l    d1
  617.         add.l    d1,d0
  618.         move.l    d0,($c6,a2)
  619.         movem.l    (a7)+,d2/a2-a3        ;original
  620.         rts
  621.  
  622. ;============================================================================
  623. ;  $34 execbase
  624. ;  $40.1 0-disk in drive 1-no disk
  625. ;  $40.4 0-readwrite 1-readonly
  626. ;  $41.7 motor status
  627. ;  $43 unit
  628. ; $126 disk change count
  629.  
  630. trd_format
  631. trd_readwrite    movem.l    d2/a1-a2,-(a7)
  632.  
  633.         moveq    #0,d1
  634.         move.b    ($43,a3),d1        ;unit number
  635.         clr.b    (IO_ERROR,a1)
  636.  
  637.         btst    #1,($40,a3)        ;disk inserted?
  638.         beq    .diskok
  639.  
  640.         move.b    #TDERR_DiskChanged,(IO_ERROR,a1)
  641.  
  642. .end        movem.l    (a7),d2/a1-a2
  643.         bsr    trd_endio
  644.         movem.l    (a7)+,d2/a1-a2
  645.         moveq    #0,d0
  646.         move.b    (IO_ERROR,a1),d0
  647.         rts
  648.  
  649. .diskok        cmp.b    #CMD_READ,(IO_COMMAND+1,a1)
  650.         bne    .write
  651.  
  652. .read        moveq    #0,d2
  653.         move.b    (_trd_disk,pc,d1.w),d2    ;disk
  654.         move.l    (IO_OFFSET,a1),d0    ;offset
  655.         move.l    (IO_LENGTH,a1),d1    ;length
  656.         move.l    (IO_DATA,a1),a0        ;destination
  657.         move.l    (_resload,pc),a1
  658.         jsr    (resload_DiskLoad,a1)
  659.         bra    .end
  660.  
  661. .write        move.b    (_trd_prot,pc),d0
  662.         btst    d1,d0
  663.         bne    .protok
  664.         move.b    #TDERR_WriteProt,(IO_ERROR,a1)
  665.         bra    .end
  666.  
  667. .protok        lea    (.disk,pc),a0
  668.         move.b    (_trd_disk,pc,d1.w),d0    ;disk
  669.         add.b    #"0",d0
  670.         move.b    d0,(5,a0)        ;name
  671.         move.l    (IO_LENGTH,a1),d0    ;length
  672.         move.l    (IO_OFFSET,a1),d1    ;offset
  673.         move.l    (IO_DATA,a1),a1        ;destination
  674.         move.l    (_resload,pc),a2
  675.         jsr    (resload_SaveFileOffset,a2)
  676.         bra    .end
  677.  
  678. .disk        dc.b    "Disk.",0,0,0
  679.  
  680. _trd_disk    dc.b    1,2,3,4            ;number of diskimage in drive
  681. _trd_prot    dc.b    WPDRIVES        ;protection status
  682.     IFD DISKSONBOOT
  683. _trd_chg    dc.b    %1111            ;diskchanged
  684.     ELSE
  685. _trd_chg    dc.b    0            ;diskchanged
  686.     ENDC
  687.  
  688. trd_motor    moveq    #0,d0
  689.         bchg    #7,($41,a3)        ;motor status
  690.         seq    d0
  691.         rts
  692.  
  693. trd_protstatus    moveq    #0,d0
  694.         move.b    ($43,a3),d1        ;unit number
  695.         move.b    (_trd_prot,pc),d0
  696.         btst    d1,d0
  697.         seq    d0
  698.         move.l    d0,(IO_ACTUAL,a1)
  699.         add.l    #$708-$6d6-6,(a7)    ;skip unnecessary code
  700.         rts
  701.  
  702. trd_endio    move.l    (_expmem,pc),-(a7)    ;jump into rom
  703.         add.l    #$29e30,(a7)
  704.         rts
  705.  
  706. tdtask_cause    move.l    (_expmem,pc),-(a7)    ;jump into rom
  707.         add.l    #$296e8,(a7)
  708.         rts
  709.  
  710. trd_task    move.b    ($43,a3),d1        ;unit number
  711.         lea    (_trd_chg,pc),a0
  712.         bclr    d1,(a0)
  713.         beq    .2            ;if not changed skip
  714.  
  715.         bset    #1,($40,a3)        ;set no disk inserted
  716.         bne    .3
  717.         addq.l    #1,($126,a3)        ;inc change count
  718.         bsr    tdtask_cause
  719. .3
  720.         bclr    #1,($40,a3)        ;set disk inserted
  721.         addq.l    #1,($126,a3)        ;inc change count
  722.         bsr    tdtask_cause
  723.  
  724. .2        rts
  725.  
  726.     IFD TRDCHANGEDISK
  727.     ;d0.b = unit
  728.     ;d1.b = new disk image number
  729. _trd_changedisk    movem.l    a6,-(a7)
  730.  
  731.         and.w    #3,d0
  732.         lea    (_trd_chg,pc),a0
  733.  
  734.         move.l    (4),a6
  735.         jsr    (_LVODisable,a6)
  736.  
  737.         move.b    d1,(-5,a0,d0.w)
  738.         bset    d0,(a0)
  739.  
  740.         jsr    (_LVOEnable,a6)
  741.  
  742.         movem.l    (a7)+,a6
  743.         rts
  744.     ENDC
  745.  
  746. ;============================================================================
  747.  
  748. dos_init    move.l    #$10001,d1
  749.         bra    _flushcache
  750.  
  751. dos_endcli    tst.l    D2            ;is -1 with EndCLI
  752.         bmi    .1
  753.         move.b    (a0,d2.l),d3        ;original
  754. .1        move.l    d3,d1            ;original
  755.         rts
  756.  
  757. dos_1        move.l    #$118,d1        ;original
  758.         bra    _flushcache
  759.  
  760. dos_LoadSeg    clr.l    (12,a1)            ;original
  761.         moveq    #12,d4            ;original
  762.         lea    (.savea4,pc),a6
  763.         move.l    a4,(a6)
  764.         lea    (.bcplend,pc),a6
  765.         rts
  766.  
  767. .savea4        dc.l    0
  768.  
  769. .bcplend    cmp.l    (.savea4,pc),a4        ;are we in dos_51?
  770.         beq    .end51
  771.         jmp    ($34128-$34134,a5)    ;call original
  772.  
  773. .end51        lea    ($34128-$34134,a5),a6    ;restore original
  774.     IFD CBDOSLOADSEG
  775.         movem.l    d0-a6,-(a7)
  776.         move.l    (a1),d0            ;d0 = BSTR FileName
  777.         tst.l    d1            ;d1 = BPTR SegList
  778.         beq    .failed
  779.         bsr    _cb_dosLoadSeg
  780. .failed        movem.l    (a7)+,d0-a6
  781.     ENDC
  782.         bsr    _flushcache
  783.         jmp    (a6)
  784.  
  785.     IFD BOOTDOS
  786. dos_bootdos
  787.     ;init boot exe
  788.         lea    (_bootdos,pc),a3
  789.         move.l    a3,(bootfile_exe_j+2-_bootdos,a3)
  790.     ;fake startup-sequence
  791.         lea    (bootname_ss_b,pc),a3    ;bstr
  792.         move.l    a3,d1
  793.     ;return
  794.         rts
  795.     ENDC
  796.  
  797. ;---------------
  798. ; performs a C:Assign
  799. ; IN:    A0 = CPTR destination name
  800. ;    A1 = CPTR directory (could be 0 meaning SYS:)
  801. ; OUT:    -
  802.  
  803.     IFD DOSASSIGN
  804. _dos_assign    movem.l    d2/a3-a6,-(a7)
  805.         move.l    a0,a3            ;A3 = name
  806.         move.l    a1,a4            ;A4 = directory
  807.         move.l    (4),a6
  808.  
  809.     ;backward compatibilty (given BSTR instead CPTR)
  810.         cmp.b    #" ",(a0)
  811.         bls    .skipname
  812.  
  813.     ;get length of name
  814.         moveq    #-1,d2
  815. .len        addq.l    #1,d2
  816.         tst.b    (a0)+
  817.         bne    .len
  818.  
  819.     ;get memory for name
  820.         move.l    d2,d0
  821.         addq.l    #2,d0            ;+ length and terminator
  822.         move.l    #MEMF_ANY,d1
  823.         jsr    (_LVOAllocMem,a6)
  824.     IFD DEBUG
  825.         tst.l    d0
  826.         beq    _debug3
  827.     ENDC
  828.         move.l    d0,a0
  829.         move.b    d2,(a0)+
  830. .cpy        move.b    (a3)+,(a0)+
  831.         bne    .cpy
  832.         move.l    d0,a3
  833. .skipname
  834.     ;get memory for node
  835.         move.l    #DosList_SIZEOF,d0
  836.         move.l    #MEMF_CLEAR,d1
  837.         jsr    (_LVOAllocMem,a6)
  838.     IFD DEBUG
  839.         tst.l    d0
  840.         beq    _debug3
  841.     ENDC
  842.         move.l    d0,a5            ;A5 = DosList
  843.  
  844.     ;open doslib
  845.         lea    (_dosname,pc),a1
  846.         jsr    (_LVOOldOpenLibrary,a6)
  847.         move.l    d0,a6
  848.  
  849.     ;lock directory
  850.         move.l    a4,d1
  851.         move.l    #ACCESS_READ,d2
  852.         jsr    (_LVOLock,a6)
  853.         move.l    d0,d1
  854.     IFD DEBUG
  855.         beq    _debug3
  856.     ENDC
  857.         lsl.l    #2,d1
  858.         move.l    d1,a0
  859.         move.l    (fl_Task,a0),(dol_Task,a5)
  860.         move.l    d0,(dol_Lock,a5)
  861.  
  862.     ;init structure
  863.         move.l    #DLT_DIRECTORY,(dol_Type,a5)
  864.         move.l    a3,d0
  865.         lsr.l    #2,d0
  866.         move.l    d0,(dol_Name,a5)
  867.  
  868.     ;add to the system
  869.         move.l    (dl_Root,a6),a6
  870.         move.l    (rn_Info,a6),a6
  871.         add.l    a6,a6
  872.         add.l    a6,a6
  873.         move.l    (di_DevInfo,a6),(dol_Next,a5)
  874.         move.l    a5,d0
  875.         lsr.l    #2,d0
  876.         move.l    d0,(di_DevInfo,a6)
  877.  
  878.         movem.l    (a7)+,d2/a3-a6
  879.         rts
  880.     ENDC
  881.  
  882. ;============================================================================
  883.  
  884.     IFD HDINIT
  885.  
  886. hd_init        lea    -1,a2                ;original A2 = -1
  887.  
  888.     INCLUDE    Sources:whdload/kickfs.s
  889.     
  890.     ENDC
  891.  
  892. ;============================================================================
  893.  
  894. _flushcache    move.l    (_resload,pc),-(a7)
  895.         add.l    #resload_FlushCache,(a7)
  896.         rts
  897.  
  898. ;============================================================================
  899.  
  900.     IFD DEBUG
  901. _debug1        tst    -1    ;unknown packet (=d2) for dos handler
  902. _debug2        tst    -2    ;no lock given for a_copy_dir (dos.DupLock)
  903. _debug3        tst    -3    ;error in _dos_assign
  904. _debug4        tst    -4    ;invalid lock specified
  905.         illegal        ;security if executed without mmu
  906.     ENDC
  907.  
  908. ;============================================================================
  909.  
  910. slv_kickname    dc.b    "34005.a500",0
  911. _keyboarddelay    dc.b    0
  912.     EVEN
  913. _tags        dc.l    WHDLTAG_CBSWITCH_SET
  914. _cbswitch_tag    dc.l    0
  915.         dc.l    WHDLTAG_ATTNFLAGS_GET
  916. _attnflags    dc.l    0
  917.         dc.l    WHDLTAG_MONITOR_GET
  918. _monitor    dc.l    0
  919.         dc.l    WHDLTAG_TIME_GET
  920. _time        dc.l    0
  921.     IFLT NUMDRIVES
  922.         dc.l    WHDLTAG_CUSTOM1_GET
  923. _custom1    dc.l    0
  924.     ENDC
  925.         dc.l    0
  926. _resload    dc.l    0
  927. _cbswitch_cop2lc    dc.l    0
  928.  
  929. ;============================================================================
  930.  
  931.     END
  932.